﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="BookInfo.aspx.cs" Inherits="BookInfo"  Title="猎书网-添加书籍"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script language="javascript" src="/model/jquery.validate.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){  

 $("#coverurl").bind("change", function(e){
       $("#cover").attr("src", function() { 
          return $("#coverurl").val(); 
          }
 );
    });     
// 中文字两个字节    
jQuery.validator.addMethod("byteRangeLength", function(value, element, param) {    
  var length = value.length;    
  for(var i = 0; i < value.length; i++){    
   if(value.charCodeAt(i) > 127){    
    length++;    
   }    
  }    
  return this.optional(element) || ( length >= param[0] && length <= param[1] );    
});    
// 字符验证    
jQuery.validator.addMethod("charCheck", function(value, element) {    
  return this.optional(element) || /^[\u0391-\uFFE5\w]+$/.test(value);    
});    
jQuery.validator.addMethod("remCheck", function(value, element) {
  var t=true;
  value=value.toLowerCase();
  if(value.indexOf('script')>=0||value.indexOf('frame')>=1)
    t=false;      
  return this.optional(element) || t;    
}); 
$(myForm).validate({    
/* 设置验证规则 */    
  rules: {   
    bookname: {    
    required: true,    
    charCheck: true,    
    byteRangeLength: [2,100],
    remote: {
        url: "/BookInfo.aspx",
        type: "post",
        data: {
            lb:"checkbook",
            bookname: function() {
            return $("#bookname").val();
          }
        }
      }

   },   
   writer: {    
    required: true,
    charCheck:true,
    byteRangeLength: [2,50]
   },
   coverurl: {    
    required: true,
    url:true,
    byteRangeLength: [2,50] 
   },   
   rem: {    
    required: true,
    remCheck:true,
    byteRangeLength: [10,500]
   },
   confirm:{
    required:true,
    minlength:4,
    maxlength:4
   }
  },    
  messages: {   
   bookname: {    
    required: "请填写书名",  
    charCheck:"书名只允许存在字母、数字、下划线",
    byteRangeLength: jQuery.format("用户名必须{0}-{1}个字符之间(一个中文字算2个字符)"),
    remote: jQuery.format("书籍已存在")
   },  
   writer: {    
    required: "请填写密码",   
    charCheck:"作者只允许存在字母、数字、下划线", 
    byteRangeLength: jQuery.format("作者必须{0}-{1}个字符之间(一个中文字算2个字符)") 
   },  
   coverurl: {    
    required: "请填写封面地址",  
    url:"请填写正确的URL地址",  
    byteRangeLength: jQuery.format("封面地址必须{0}-{1}个字符之间") 
   },   
   rem: {    
    required: "请输入书籍简介",
    remCheck:"禁用“script”与“frame”",
    byteRangeLength:jQuery.format("简介长度不得多于{0}字符.")   
   },  
   confirm:{
    required:"请输入验证码",
    minlength: "验证码为4位的",
    maxlength:"验证码是4位的"
   } 
  },    
/* 错误信息的显示位置 */    
  errorPlacement: function(error, element) {    
    error.appendTo( element.parent() );      
  },    
  success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		},
  submitHandler: function(form) { 
    $.ajax({ url: 'BookInfo.aspx',
            type: 'POST',
            data: { lb: "add", booktype:$("#select_booktype").val(),bookname: $("#bookname").val(),writer:$("#writer").val(),coverurl:$("#coverurl").val(),rem:$("#rem").val(),confirm:$("#confirm").val()},
            dataType: 'html',
            timeout: 1000,
            error: function() { alert('未知错误'); },
            success: function(data) { 
              if(data=="尚未登录"){
                 window.location="/Login.aspx";
              }
              else
                window.location="/BookInfo.aspx?BookID="+data;
            }
            }); 
    }    //end of submitHandler
});     
   
}); 
</script>
    <style type="text/css">
        #coverurl
        {
            width: 355px;
        }
        .style1
        {
            width:200px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="myForm" action="#">
<table cellspacing="0" cellpadding="0" class="myTable myFormTable"> 
    <tr>
    <td colspan="3" class="title">填入书籍基本信息(可以帮你在10多个网站同时查找哦！)</td>
    </tr>
    <tr>
      <th>书名：</th>
      <td colspan="2"><input name="bookname" type="text" id="bookname" class="style1" />
      </td>
    </tr>
    <tr>
      <th>作者：</th>
      <td colspan="2"><input name="writer" type="text" id="writer" class="style1"/></td>
    </tr>
    <tr>
      <th>类型：</th>
      <td colspan="2"><% Response.Write(WebMake.getTypeSelect("0")); %></td>
    </tr>
    <tr>
      <th width="25%">封面：</th>
      <td width="10%" style="text-align:center">
          <img alt="" src="/image/noimage.gif" width="100" height="112" id="cover" /></td>
      <td width="65%" style="vertical-align:bottom">路径：<input name="coverurl" type="text" 
              id="coverurl" value="http://www.lieshu.net/image/noimage.gif" /></td>
    </tr>
    <tr>
      <th>介绍：</th>
      <td colspan="2"><textarea name="rem" id="rem" cols="60" rows="10"></textarea></td>
    </tr>
    <tr>
      <th>验证：</th>
      <td colspan="2"><input name="confirm" type="text" id="confirm" style="width:50px;" />
      <asp:Image Runat="server" ID="ImageCheck" ImageUrl="ValidateCode.aspx"></asp:Image>
      </td>
    </tr>
  </table>
<div ><input id="addbook" type="submit" value="添加书籍" /></div>
</form>
</asp:Content>
